package com.cmcc.linlaker.map;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;

import com.cmcc.linlaker.ui.query.ProjectDetailActivity;
import com.tianditu.android.maps.GeoPoint;
import com.tianditu.android.maps.MapView;
import com.tianditu.android.maps.MapViewRender;
import com.tianditu.android.maps.Overlay;
import com.tianditu.android.maps.renderoption.DrawableOption;

import javax.microedition.khronos.opengles.GL10;

public class MOverlay extends Overlay {
    private Drawable mDrawable;
    private DrawableOption mDrawableOption;
    private GeoPoint mGeoPoint;
    private Context context;

    public MOverlay(Context context, GeoPoint mGeoPoint, int res) {
        this.context = context;
        this.mGeoPoint = mGeoPoint;

        mDrawable = context.getResources().getDrawable(res);
        mDrawableOption = new DrawableOption();
        //设置锚点位置
        mDrawableOption.setAnchor(0.5f, 1.0f);
        //设置旋转角度
        mDrawableOption.setRotate(0);
        //设置状态
        mDrawableOption.setState(DrawableOption.STATE_NORMAL);
        //设置多少帧刷新一次图片资源
        mDrawableOption.setPeriod(200);
    }

    @Override
    public boolean draw(GL10 gl, MapView mapView, boolean shadow, long when) {
        MapViewRender render = mapView.getMapViewRender();
        render.drawDrawable(gl, mDrawableOption, mDrawable, mGeoPoint);
        return true;
    }

    @Override
    public boolean onTap(GeoPoint p, MapView mapView) {
        //指定当前点击的位置添加覆盖物，也可以自己指定
        mGeoPoint = p;
        return true;
    }
}